from client.ApiClient import client


class FileService:

    @classmethod
    def upload_file(cls, file_path) -> str:
        # 确保文件存在
        if not file_path.exists():
            raise FileNotFoundError(f"文件未找到: {file_path}")

        with open(file_path, "rb") as file:
            file_object = client.files.create(file=file, purpose="file-extract")

        return file_object.id

    @classmethod
    def get_file_content(cls, file_id) -> str:
        file_data = client.files.content(file_id=file_id)
        return file_data.text
